package handler

import (
	"github.com/gin-gonic/gin"
	"monthly-test/api/request"
	"monthly-test/internal/dao"
	"monthly-test/internal/model"
	"net/http"
)

func ListViper(c *gin.Context) {
	var req request.ListViper
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "验证失败",
			"date": err.Error(),
		})
		return
	}
	//var viper model.Viper
	//
	//viperList := dao.GetListByFields(&viper.Id, &model.Viper{
	//	Viper: req.Viper,
	//	Image: req.Image,
	//	File:  req.File,
	//})
	//for _, m := range viperList {
	//	list = append(list, &model.Viper{
	//		Viper: m.Viper,
	//		Image: m.Image,
	//		File:  m.File,
	//	})
	//}

	list := model.Viper{
		Viper: "1",
		Image: "1",
		File:  "1",
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "ok",
		"date": list,
	})
}

func AddViper(c *gin.Context) {
	var req request.ListViper
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "验证失败",
			"date": err.Error(),
		})
		return
	}
	dao.Create(&model.Viper{
		Viper: req.Viper,
		Image: req.Image,
		File:  req.File,
	})
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "ok",
		"date": nil,
	})
}
